#!/usr/bin/python3
import os
from shutil import copyfile
import datetime
import random

def find_File(file):
    for root, dirs, files in os.walk(file):
        # 遍历文件
        for file in files:
            filePath = root + '/' + file
            fileContentList = filePath.replace(']','[').split(']')
            print(fileContentList)
            #     newFileName = '_'.join(fileContentList[len(fileContentList) - 3: len(fileContentList)])
            #     # if os.path.exist(newFileFolderPath):
            #     copyfile(filePath, newFileFolderPath + '/' + newFileName)
            #     print("Move CPP File Success：%s -> %s" %(filePath, newFileFolderPath + '/' + newFileName))

def move_file(file):
    moveCPPFile = [""]
    for root, dirs, files in os.walk(file):
        # 遍历文件
        for file in files:
            filePath = root + '/' + file
            fileContentList = filePath.replace('\\','/').split('/')
            print(fileContentList)
            if 3 < len(fileContentList):
                newFileFolderPath = '/'.join(fileContentList[0: len(fileContentList) - 3])
                newFileName = '_'.join(fileContentList[len(fileContentList) - 3: len(fileContentList)])
                # if os.path.exist(newFileFolderPath):
                copyfile(filePath, newFileFolderPath + '/' + newFileName)
                print("Move CPP File Success：%s -> %s" %(filePath, newFileFolderPath + '/' + newFileName))


with open('todo.txt','a',encoding='utf8') as file:
    random_num = random.randint(1,10000)
    current_time = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
    file.writelines("当前时间：{} 随机数值：{}\n".format(current_time, random_num))

if __name__ == '__main__':
    move_file("/data/code/C++/Linux_C_C++/")

